<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RoadShowApply extends Model
{
    //
    protected $table = 'roadshow_apply';

    protected $fillable = array('uid', 'maker_id','initiator');

    protected function getDateFormat()
    {
        return date(time());
    }
    public function roadshowproject(){
        return $this->belongsToMany('App\Models\RoadshowProject','roadshow_project','project_id','roadshow_apply_id');
    }
    public function maker(){
        return $this->hasOne('App\Models\Maker','id','maker_id');
    }

    public function user(){
        return $this->belongsTo('App\Models\User','uid','uid');
    }

    public function project(){
        return $this->belongsTo('App\Models\Project','project_id','id');
    }

    /**
     * 检查项目是否正在路演 只有个人的时候
     */
    static function checkRoadshow($project_ids,$initiator,$uid){
        //if($initiator == 'maker'){
        //	return false;
        //}else{
        $project_id = isset($project_ids[0])? $project_ids[0]:0;
        $res = self::where('uid', $uid)->where('status', 0)->get();
        if(count($res)){
            foreach($res as $k=>$v){
                if(RoadshowProject::checkRoadshowProject($project_ids[0], $v->id)){
                    return true;
                }
            }
        }
        return false;
        //}
    }
}
